package cloudGateway.model;

import cloudEntity.entity.SmartUserEntity;
import cloudEntity.vo.SmartUserLoginVO;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * @program: Smart School
 * @ClassName LoginUser
 * @description:
 * @author: 陈智博
 * @create: 2025-04-11 08:59
 * @Version 1.0
 **/
public class LoginUser implements UserDetails {

    private SmartUserEntity smartUserEntity;

    private List<String> permission;

    public LoginUser(SmartUserEntity smartUserEntity, List<String> permission) {
        this.smartUserEntity = smartUserEntity;
        this.permission = permission;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return AuthorityUtils.createAuthorityList(permission);
    }

    @Override
    public String getPassword() {
        return smartUserEntity.getSysUserPassword();
    }

    @Override
    public String getUsername() {
        return smartUserEntity.getSysUserUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public SmartUserEntity getSmartUserEntity() {
        return smartUserEntity;
    }

    public void setSmartUserEntity(SmartUserEntity smartUserEntity) {
        this.smartUserEntity = smartUserEntity;
    }

    public List<String> getPermission() {
        return permission;
    }

    public void setPermission(List<String> permission) {
        this.permission = permission;
    }

    @Override
    public String toString() {
        return "LoginUser{" +
                "smartUserEntity=" + smartUserEntity +
                ", permission=" + permission +
                '}';
    }
}
